package com.netcracker.automonic.parser;

import java.io.IOException;

import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

/**
 * Parent of parsers,that use <a href="http://jsoup.org/">JSoup</a> library
 * 
 * @author lester
 * 
 */
public abstract class JsoupParser {

	private static final Logger log = Logger.getLogger(JsoupParser.class);
	Document doc;
	String URL;

	/**
	 * Returns the next page(HTML Document) if it exist,else returns null
	 * 
	 * @return HTML Document of next page
	 */
	abstract Document getNextPage();

	/**
	 * Get HTML Document by the specified {@link #URL} address
	 * 
	 * @return parsed Document
	 */
	Document getDocumentByConnect() {
		try {
			doc = Jsoup.connect(URL).get();
			return doc;
		} catch (IOException e) {
			log.trace("Error when connect", e);
			return null;
		}
	}
}
